﻿using System.Collections;
using System.Web.UI.WebControls;
using ASPNETVN.PORTAL.Components.Configuration.Settings;
using ASPNETVN.PORTAL.Components.UI;
using System;
using ASPNETVN.PORTAL.Components.Security;
using ASPNETVN.PORTAL.Components.Helpers;
using ASPNETVN.PORTAL.Components.UI.DataTypes;
using System.Web.UI;

namespace ASPNETVN.PORTAL.Modules.FEEDBACK
{

    public enum ModulePages
    {
        SendFeedback,
        SendFeedbackCompleted,
        ItemManager
    }

    public partial class Main : PortalModuleControl
    {
        public Main()
        {
            // Cách thức lưu trữ file upload.
            ArrayList listStorageType = new ArrayList();
            listStorageType.Add(new ListItem("Database", "DATABASE"));
            listStorageType.Add(new ListItem("Link", "LINK"));
            listStorageType.Add(new ListItem("File", "FILE"));

            ModuleSettingItem setting = new ModuleSettingItem(new CustomListDataType(listStorageType, "Text", "Value"));
            setting.Value = "DATABASE";
            setting.Name = "Storage Type";
            setting.Description = "Storage Type";
            setting.SortOrder = 1;
            this.BaseSettings.Add("StorageType", setting);

            setting = new ModuleSettingItem(new StringDataType());
            setting.Value = "Default.aspx?tabid=" + Guid.Empty.ToString();
            setting.Name = "Link Management Page";
            setting.Description = "Link Management Page";
            setting.SortOrder = 1;
            this.BaseSettings.Add("FEEDBACK.LinkManagement", setting);
        }

        private void LoadChildControl()
        {
            const string basePath = "~/Modules/ASPNETVN.PORTAL.Modules.FEEDBACK/";
            const string pageQuery = "page";
            string pageName = Request.QueryString[pageQuery];

            ModulePages page = ModulePages.SendFeedback; ;
            if (pageName != null)
            {
                page = (ModulePages)Enum.Parse(typeof(ModulePages), Request.QueryString[pageQuery], true);
            }

            string src = string.Format("{0}Controls/{1}.ascx", basePath, page);
            ModulePage ctl = (ModulePage)this.LoadControl(src);
            ctl.ParentControl = this;
            ContentPane.Controls.Add(ctl);
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.ModuleTitle.AddUrl = HttpUrlBuilder.BuildShareUrl(this.ModuleID, 0, "CategoryManager");
            //this.ModuleTitle.ManagerUrl = HttpUrlBuilder.BuildAddEditUrl(this.ModuleID, 0, "ItemManager");            
            this.ModuleTitle.ManagerUrl = this.Settings["FEEDBACK.LinkManagement"].ToString() != "Default.aspx?tabid=" + Guid.Empty.ToString() ?
                this.Settings["FEEDBACK.LinkManagement"].ToString() : "#"; //"Default.aspx?tabid=478d0da6-4d75-47ff-a8aa-1c9457bfb180";
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.LoadChildControl();
        }

    }
}